#ifndef CALCULATION_SERVER_H
#define CALCULATION_SERVER_H

#include <exception>
#include "shared_ptr.h"
#include "matrix.h"
#include "job.h"
#include "Similarity.h"
#include "SolveEquationSystem.h"
#include "Polynomial.h"
#include "list.h"
using namespace mtm;
class CalculationServer{
	List<shared_ptr<Job> > jobList;
	int counter;
public:
	typedef enum { SOLVE_EQUATION_SYSTEM, SIMILARITY, POLYNOMIAL } JobType;	

	class CalculationServerException : public std::exception {};
	class OperationFailed : public CalculationServerException {};	
	class JobNotFound : public CalculationServerException {};
	class InvalidPriority : public CalculationServerException {};
	
	CalculationServer();

	/* Adds a new job to the server's jobs */
	int addJob(JobType type, int priority, const Matrix& A, const Matrix& B);

	/* Removes the job with id = jobindex from the server's job.
	   Should remove all pending jobs to that job as well. */
	void removeJob(int jobindex);

	/* Changes the priority of the job with id = jobindex to newPriority */
	void changePriority(int jobindex, int newPriority);

	/* executes the next job in queue. Returns the matrix calculated by the job. */
	Matrix execute();

	/* Returns the index of the next job to be performed. */
	int nextJob();

	/* Returns the total number of jobs in the queue. */
	int totalJobs();
};

#endif
